package com.bawei.module_shop.address;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bawei.library_base.RouterPath;
import com.bawei.library_base.mvp.v.BaseActivity;
import com.bawei.library_base.room.address.Address;
import com.bawei.library_base.room.address.AddressDao;
import com.bawei.library_base.room.address.AddressDatabase;
import com.bawei.module_shop.R;
import com.blankj.utilcode.util.ToastUtils;

import org.greenrobot.eventbus.EventBus;

@Route(path = RouterPath.NewAddress.NEWADDRESS)
public class NewAddressActivity extends BaseActivity {



    private EditText mShipNameEt;
    private EditText mShipMobileEt;
    private EditText mShipAddressEt;
    private Button mSaveBtn;

    @Override
    public int beanLayout() {
        return R.layout.activity_new_address;
    }

    @Override
    public void initView() {


        mShipNameEt = (EditText) findViewById(R.id.mShipNameEt);
        mShipMobileEt = (EditText) findViewById(R.id.mShipMobileEt);
        mShipAddressEt = (EditText) findViewById(R.id.mShipAddressEt);
        mSaveBtn = (Button) findViewById(R.id.mSaveBtn);
    }

    @Override
    public void initData() {
        //收货地址数据库
        AddressDao addressDao = AddressDatabase.getInstance(this).getAddressDao();
        mSaveBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    String s = mShipAddressEt.getText().toString();
                    String s1 = mShipNameEt.getText().toString();
                    String s2 = mShipMobileEt.getText().toString();


                    Log.i("66666666666TAG", "onClick: "+s+s1+s2);

                    if (s.isEmpty()&&s1.isEmpty()&&s2.isEmpty()){
                        ToastUtils.showShort("没有填写完整 ，请补充");
                    }else {
                        ToastUtils.showShort("添加成功");
                        //添加成功
                        Address address = new Address();
                        address.setName(s1);
                        address.setPhone(s2);
                        address.setFrom(s);
                        addressDao.insert(address);
                        EventBus.getDefault().post("addSuccess");
                        finish();

                    }
                }
            });
    }
}